package mblog.velocity.directive;

import mblog.base.context.SpringContextHolder;
import mblog.core.data.Post;
import mblog.core.persist.service.PostService;
import mblog.velocity.BaseDirective;
import mblog.velocity.handler.RenderHandler;

import java.io.IOException;
import java.util.List;

/**
 * Project  : mblog
 * Author   : Wu Tian Qiang
 * Date     : 2016/6/12
 */
public class CarouselDirective extends BaseDirective {

    private PostService postService;

    @Override
    public void initBean() {
        postService = SpringContextHolder.getBean(PostService.class);
    }

    @Override
    public boolean render(RenderHandler handler) throws RuntimeException, IOException {

        String alias = handler.getStringParameter(0);

        List<Post> posts = postService.findFeatureds();
        handler.put(alias, posts);
        handler.doRender();

        postRender(handler.getContext());
        return true;
    }

    @Override
    public String getName() {
        return "carousel";
    }

    @Override
    public int getType() {
        return BLOCK;
    }
}
